package com.ayz.gateway.core.datasource.unpooled;


import com.ayz.gateway.core.context.config.Configuration;
import com.ayz.gateway.core.datasource.Datasource;
import com.ayz.gateway.core.datasource.DatasourceFactory;
import com.ayz.gateway.core.datasource.DatasourceType;
import lombok.Data;

/**
 * @ClassName UnpooledDatasourceFacotry
 * @Description TODO: 非池化连接数据源单例工厂类
 * 当前DatasourceFactory工厂类应该在一个网关上下文中单例
 * @Author 快乐的星球
 * @Date 2023/5/9 11:52
 * @Version 1.0
 **/
@Data
public class UnpooledDatasourceFactory implements DatasourceFactory {
    /**
     * 网关上下文配置项
     */
    private Configuration configuration;
    /**
     * 数据源类型
     */
    private DatasourceType datasourceType;

    /**
     * 非池化的连接数据源
     */
    private UnpooledDatasource unpooledDatasource;
    public UnpooledDatasourceFactory(Configuration configuration, DatasourceType datasourceType) {
        this.configuration = configuration;
        this.datasourceType = datasourceType;
        this.unpooledDatasource=new UnpooledDatasource(datasourceType,configuration);
    }

    @Override
    public void setConfiguration(Configuration configuration) {
        this.configuration=configuration;
    }
    @Override
    public Datasource getDatasource() {
        return this.unpooledDatasource;
    }

    @Override
    public void setDatasourceType(DatasourceType datasourceType) {
        this.datasourceType=datasourceType;
    }
}
